
interface SchemaFormat {
    /**
     * 格式化
     * example: date date-time email uri ...
     */
    format?:string
}
interface SchemaDefault<T> {
    /**
     * 默认值
     */
    default?:T
}
interface SchemaTitle {
    /**
     * 标题
     */
    title?:string
}
interface SchemaDescription {
    /**
     * 描述
     */
    description?:string
}
interface SchemaExample<T> {
    /**
     * 一些案例
     */
    examples?:T[]
}
interface SchemaReadOnly {
    /**
     * 是否只读
     */
    readonly?:boolean
}
interface SchemaWriteOnly {
    /**
     * 是否只写
     */
    writeonly?:boolean
}
export interface ObjectSchema extends SchemaDescription,SchemaTitle,SchemaDefault<Record<string,any>>,SchemaExample<Record<string,any>>,SchemaReadOnly,SchemaWriteOnly {
    type:"object"
    /**
     * 对象中必填属性
     */
    required?:string[]
    /**
     * 对象属性
     */
    properties:Record<string,Schema>
}

interface StringSchema  extends SchemaFormat,SchemaDefault<string>,SchemaTitle,SchemaDescription,SchemaExample<string>,SchemaReadOnly,SchemaWriteOnly{
    type:"string"
    /**
     * 校验用的正则
     */
    pattern?:string
    /**
     * 字符串最小长度
     */
    minLength?:number
    /**
     * 字符串最大长度
     */
    maxLength?:number
    /**
     * 枚举值
     */
    enum?:string[]
}

interface IntegerSchema extends SchemaFormat,SchemaDefault<number>,SchemaTitle,SchemaDescription,SchemaExample<number>,SchemaReadOnly,SchemaWriteOnly {
    type:"number"
    /**
     * 最大值
     */
    maximum?:number
    /**
     * 最小值
     */
    minimum?:number
}

interface BooleanSchema extends SchemaFormat,SchemaDefault<boolean>,SchemaTitle,SchemaDescription,SchemaExample<boolean>,SchemaReadOnly,SchemaWriteOnly  {
    type:"bool"
}

interface NullSchema extends SchemaFormat,SchemaDefault<null>,SchemaTitle,SchemaDescription,SchemaExample<any>,SchemaReadOnly,SchemaWriteOnly {
    type:"null"
}

interface ArraySchema extends SchemaTitle,SchemaDescription,SchemaDefault<any[]>,SchemaExample<any[]>,SchemaReadOnly,SchemaWriteOnly {

    type:"array"

    /**
     * 元素类型
     */
    items:Schema[] | Schema
    /**
     * 数组最大个数
     */
    maxItems?:number
    /**
     * 数组最小个数
     */
    minItems?:number
}



export type Schema = ObjectSchema | StringSchema | IntegerSchema | BooleanSchema | ArraySchema | NullSchema
